package com.heima.Control;

import com.heima.poji.Emp;
import com.heima.poji.Result;
import com.heima.poji.pageBean;
import com.heima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;


@Slf4j
@RestController
public class EmpControl {
    @Autowired
    private EmpService empService;
    @GetMapping("/emps")
    public Result Page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "5") Integer pageSize,
                       String name, Short gender,
           @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,//指定前端传入得数据格式
           @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
        ){

        log.info("分页展示员工页面");
         pageBean pagebean =empService.list(page,pageSize,name,gender,begin,end);
        return Result.success(pagebean);
    }
    @DeleteMapping("/emps/{ids}")
    public Result delectById(@PathVariable List<Integer> ids){
        empService.delectById(ids);
        log.info("批量删除员工信息");
        return Result.success();
    }
    //新增员工信息
    @PostMapping("/emps")
    public Result insetEmp(@RequestBody Emp emp){
        log.info("新增员工信息");
        empService.insetEmp(emp);
        return Result.success();
    }

    @GetMapping("/emps/{id}")
    public Result SelctById(@PathVariable Integer id){
        log.info("回显展示员工信息");
       // empService.SelctById(id);
        return Result.success(empService.SelctById(id));
    }

    @PutMapping("/emps")
    public Result updateById(@RequestBody Emp emp){
        log.info("修改员工信息");
        empService.updateById(emp);
        return Result.success();
    }

}
